$(function(){
  
 let btn=document.querySelector('.btn')
 let status=document.querySelector('#status')
 status.addEventListener('change',function(){
   let status1=this.checked
   if(!status1){
        btn.disabled=true
        btn.style.backgroundColor='#ccc'
   }else{
    btn.disabled=false
    
    btn.style.backgroundColor='#f60'
   }
 })


 let flagg = {
    user: false,
    dell: false,
    qrpwd:false
  }
//正则
let username=document.querySelector('#username')
let username1=document.querySelector('.username1')
let div1=document.querySelector('.div1')
    username.addEventListener('blur',function(){
        //获取值
        let userv=username.value
       
        //创建正则
        let zhenze = /^[a-zA-Z]\w{5,11}$/ //6-12首字符字母,后面跟数字 字母 下划线
        //验证
        let bool = zhenze.test(userv)
        if(bool){
            div1.style.border = '1px solid #ccc'; 
            username1.innerHTML = '';
            flagg.user=true
        }else{
            username1.innerHTML = '6-12以字母开头,后面跟数字 字母 下划线';
            div1.style.border = '1px solid red';
            flagg.user=false
        }
    })
    let pwd=document.querySelector('#pwd')
    let pwd1=document.querySelector('.pwd1')
    let div2=document.querySelector('.div2')
    pwd.addEventListener('blur',function(){
            //获取值
            let userv=pwd.value
            //创建正则
            let zhenze =/^(\w){6,20}$/ //只能输入6-20个字母、数字、下划线 
            //验证
            let bool = zhenze.test(userv)
            if(bool){
                div2.style.border = '1px solid #ccc'; 
                pwd1.innerHTML = '';
                flagg.dell=true
            }else{
                pwd1.innerHTML = '只能输入6-20个字母、数字、下划线 ';
                div2.style.border = '1px solid red';
                flagg.dell=false
            }
        })
        let qrpwd=document.querySelector('#qrpwd')
        let qrpwd1=document.querySelector('.qrpwd1')
        let div3=document.querySelector('.div3')
        qrpwd.addEventListener('blur',function(){
                //获取值
                let userv=pwd.value
                let qrpwd22=qrpwd.value
                if(userv===qrpwd22){
                    div3.style.border = '1px solid #ccc';
                    qrpwd1.innerHTML = '';
                    flagg.qrpwd=true
                }else{
                    div3.style.border = '1px solid red';
                    qrpwd1.innerHTML = '2次密码输入不一致';
                    flagg.qrpwd=false
                }
               
               
                
            })

    let  loginForm=document.querySelector('#myform')
    loginForm.addEventListener('submit',function(){
        if(flagg.user===false){
            username1.innerHTML = '6-12以字母开头,后面跟数字 字母 下划线';
            div1.style.border = '1px solid red';
            event.preventDefault(); 
        }
        if( flagg.dell===false){
            pwd1.innerHTML = '只能输入6-20个字母、数字、下划线 ';
            div2.style.border = '1px solid red';
            event.preventDefault();  
        }
        if( flagg.qrpwd===false){
            div3.style.border = '1px solid red';
            qrpwd1.innerHTML = '2次密码输入不一致';
            event.preventDefault();
        }
    })
})